
clear
*Calling the data 2015_2020

* import spss using  ".\", clear

use "/Users/scottmorgenstern/Library/CloudStorage/OneDrive-UniversityofPittsburgh/_LA elite survey PELA (Salamanca)/_annual survey versions/2019/Brazil BANCO LEGISLATURA 2015_2019 com peso"
 
*****************************************************************
* Recoding Variables
***************************************************************** 

 
 
 */
gen wave=4
*drop legis 
gen legis = 2020
rename Partido partido
gen nestu =9999

* Ideology 
gen ID1=v57
replace ID1=. if  ID1>11
* Ideology Party
gen ID2=v58
replace ID2=. if  ID2>11

* for Brazil it is a 1-9 scale! 


// Attendance to church
*gen church_attend=RE1b

*gen regular=1 if RE1b==3 | RE1b==4 | RE1b==5
*replace regular=0 if RE1b==1 | RE1b==2 

*--------------------------
* Party
*--------------------------
gen party = "."


replace party="BR PRB" if partido==10
replace party ="BR PP" if partido==11
replace party ="BR PDT" if partido==12
replace party ="BR PT" if partido==13
replace party ="BR PTB" if partido==14
replace party ="BR MDB" if partido==15
replace party ="BR PSL" if partido==17
replace party ="BR PODEMOS" if partido==19
replace party ="BR PS" if partido==20
replace party ="BR PR" if partido==22
replace party ="BR PPS" if partido==23
replace party ="BR DEM" if partido==25
replace party ="BR PHS" if partido==31
replace party ="BR PSB" if partido==40
replace party ="BR PSDB" if partido==45
replace party ="BR PSOL" if partido==50
replace party ="BR PSD" if partido==55
replace party ="BR PCdoB" if partido==65
replace party ="BR SD" if partido==77
replace party ="BR PROS" if partido==90


drop partido 

gen partido=party

*--------------------------
* Abortion
*--------------------------
*reverse order for brazil
gen abortreverse=1 if v59f==10
replace abortreverse=2 if v59f==9
replace abortreverse=3 if v59f==8
replace abortreverse=4 if v59f==7
replace abortreverse=5 if v59f==6
replace abortreverse=6 if v59f==5
replace abortreverse=7 if v59f==4
replace abortreverse=8 if v59f==3
replace abortreverse=9 if v59f==2
replace abortreverse=10 if v59f==1


*replace v59f =. if v59f>10
gen VAL2_2=abortreverse
gen val_abortion=round(VAL2_2)


lab define VAL221 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL221

*--------------------------
* Immigration
*--------------------------

/* replace INM101 =. if INM101>6
gen val_imm=INM101
lab define VAL21 ///
	1 "Totally against" ///
	5 "Totally agree"
lab val val_imm VAL21
*/

*--------------------------
* SSM
*--------------------------
gen ssmreverse=1 if v59b==10
replace ssmreverse=2 if v59b==9
replace ssmreverse=3 if v59b==8
replace ssmreverse=4 if v59b==7
replace ssmreverse=5 if v59b==6
replace ssmreverse=6 if v59b==5
replace ssmreverse=7 if v59b==4
replace ssmreverse=8 if v59b==3
replace ssmreverse=9 if v59b==2
replace ssmreverse=10 if v59b==1

*replace VAL1 =. if VAL1>10
gen val_ssm=ssmreverse
lab define VAL1 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_ssm VAL1

*--------------------------
* Drugs
*--------------------------
gen drugseverse=1 if v59d==10
replace drugseverse=2 if v59d==9
replace drugseverse=3 if v59d==8
replace drugseverse=4 if v59d==7
replace drugseverse=5 if v59d==6
replace drugseverse=6 if v59d==5
replace drugseverse=7 if v59d==4
replace drugseverse=8 if v59d==3
replace drugseverse=9 if v59d==2
replace drugseverse=10 if v59d==1


gen VAL3=drugseverse
replace VAL3 =. if VAL3>10
gen val_drugs=VAL3

lab val val_drugs VAL1

*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
* note earlier version excluded this, because Brazil asks if the person is "adepto a alguna relgion" while ohter
*countries ask: "eres creyente?"



gen religious=1 if v60==1
replace religious=2 if v60==2
replace religious=. if v60>3

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel
* again, note Brazil is differnet than other countries for question


*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if v61==4
replace rel_evangelical=0 if  rel_evangelical~=1

*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if v61==1
replace rel_catholic=0 if  rel_catholic~=1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=.

*--------------------------
* Education
*--------------------------
gen education= v65 if  v65<9
replace education =5 if v65==4
replace education =6 if v65==5

* note that Brazil is a bit different than others; scale to 5 not 6

lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312

*--------------------------
* Gender
*--------------------------
gen female=1 if v62==2
replace female=0 if v62==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=v63 if v63<100

*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated=v24
lab define EMI_2 ///
	1 "State" ///
	10 "Market"
lab val eco_regulated EMI_2

*-----------------------
* Free education university
*-----------------------

 * reverse scale again!!! & 1-10 not 1-7
 
gen eco_education_u=v27e if  v27e<11
replace eco_education=eco_education*7/10
lab define eco_education_u ///
	1 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u

*-----------------------
* State should reduce inequality
*-----------------------
gen eco_inequality=v27f  if  v27f<11
replace eco_inequality=eco_inequality*7/10


lab val eco_inequality eco_education_u

*-----------------------
* State should create employment
*-----------------------
/* gen eco_employment=ROES103   if  ROES103 <8

lab val eco_employment eco_education_u
*/
*-----------------------
* State companies
*-----------------------
gen eco_companies=v27a    if v27a  <11

replace eco_companies=eco_companies*7/10


lab val eco_companies eco_education_u

*-----------------------
* State wellbeing
*-----------------------
gen eco_wellbeing=v27b     if  v27b   <11
replace eco_wellbeing=eco_wellbeing*7/10


lab val eco_wellbeing eco_education_u

*-----------------------
* State health
*-----------------------
gen eco_health=v27d      if  v27d    <11
replace eco_health=eco_health*7/10


lab val eco_health eco_education_u

*-----------------------
* Pensions
*-----------------------
gen eco_pensions=v27c       if  v27c     <11
replace eco_pensions=eco_pensions*7/10


lab val eco_pensions eco_education_u



// Labeling variables
{
	
lab var nestu "Study number"
gen pais="Brazil" 
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
*lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
* note earlier version excluded this, because Brazil asks if the person is "adepto a alguna relgion"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
lab var val_drugs "Opinion about drug legalization (1-10 scale, 10 most in favor)"
*lab var val_imm "Immigrants compete for natives' jobs (1 disagree, 5 agree)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_inequality "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
*lab var eco_employment "Employment creation (1-7, 7 in favor)"
lab var eco_pensions "Pension"
lab var eco_health "Whether the state should own provide health services  (1, 7 in favor)"
lab var eco_wellbeing "Whether the state should guarantee basic wellbeign  (1, 7 in favor)"
lab var eco_companies "Whether the state should own companies  (1, 5)"

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	gen church_attend=.
	gen eco_employment=.
	*gen religious=.
	*see earlier notes; religion is handled differently in Brazil than other countries
	gen val_imm=.
	
	keep wave nestu pais partido legis ID1 ID2 church_attend religious rel_evangelical rel_catholic rel_other val_abortion val_ssm val_drugs val_imm eco_regulated education female age eco_inequality eco_education_u eco_employment eco_pensions eco_health eco_wellbeing eco_companies

}
replace ID1=. if ID1>10
replace ID2=. if ID1>10

replace religious=. if religious>2

*****************************************************************
* Save
***************************************************************** 
save "/Users/scottmorgenstern/Library/CloudStorage/OneDrive-UniversityofPittsburgh/_LA elite survey PELA (Salamanca)/Pitt projects/_PELA 2022/consolidated surveys/Brazil2015to2020.dta", replace

*****************************************************************
* Append
***************************************************************** 
{
	cd  "/Users/scottmorgenstern/Library/CloudStorage/OneDrive-UniversityofPittsburgh/_LA elite survey PELA (Salamanca)/Pitt projects/_PELA 2022/consolidated surveys"
	
 
append using  "Brazil2003to2007.dta", force
append using  "Brazil2007to2010.dta", force
append using  "Brazil2011to2014.dta", force
*append using  "Brazil2015to2020.dta", force


drop pais
gen pais = "Brazil"

save "/Users/scottmorgenstern/Library/CloudStorage/OneDrive-UniversityofPittsburgh/_LA elite survey PELA (Salamanca)/Pitt projects/_PELA 2022/consolidated surveys/Brazil_2000_2020.dta", replace
}
*****************************************************************
/* 
erase "Brazil_2015_2020.dta"
erase "Brazil_2000_2005.dta"
erase "Brazil_2010_2015.dta"
erase "Brazil_2005_2010.dta"

}

/*
* Extra Exploration data
{
******************************************************************************
* Graph setting
******************************************************************************
{
grstyle clear
set scheme s2color
grstyle init
grstyle set plain, box
grstyle color background white
grstyle set color dknavy
grstyle yesno draw_major_hgrid yes
grstyle yesno draw_major_ygrid yes
grstyle color major_grid gs8
grstyle linepattern major_grid dot
*grstyle set legend 4, box inside
grstyle color ci_area gs12%50
 graph set window fontface "Georgia"
}
 

histogram eco_regulated, by (legis partido) 


histogram val_abortion, by (legis partido) 
}
*/
